/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	///  使用物品的结果
	/// module : item
	/// </summary>
	public class UseItemResultPOD : IPOD 
    {
        public readonly static Func<UseItemResultPOD> FACTORY = () => new UseItemResultPOD();
		public static Func<UseItemResultPOD> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        /// 
        /// </summary>
        private List<ItemShowPOD> m_addItems;
		/// <summary>
        /// 
        /// </summary>
        private Dictionary<int, int> m_itemCdInfo;
		
		
        public List<ItemShowPOD> addItems
        {
            get
            {
                if(m_addItems == null)
                {
                    m_addItems = new();
                }
                return m_addItems;
            }
            private set => m_addItems = value;
        }
        public List<ItemShowPOD> unsafe_addItems
        {
        	get => m_addItems;
        	set => m_addItems = value;
        }
        public Dictionary<int, int> itemCdInfo
        {
            get
            {
                if(m_itemCdInfo == null)
                {
                    m_itemCdInfo = new();
                }
                return m_itemCdInfo;
            }
            private set => m_itemCdInfo = value;
        }
        public Dictionary<int, int> unsafe_itemCdInfo
        {
        	get => m_itemCdInfo;
        	set => m_itemCdInfo = value;
        }
		
		/*-- constructors --*/
		public UseItemResultPOD() {}
		public UseItemResultPOD(List<ItemShowPOD> addItems, Dictionary<int, int> itemCdInfo) {
			this.m_addItems = addItems;
			this.m_itemCdInfo = itemCdInfo;
		}
	      public void Serial(SOutputStream _out) {
            _out.Write_list_pod(m_addItems);
            _out.Write_map_int_int(m_itemCdInfo);
        }
        
        public void UnSerial(SInputStream _in) {
            if(!_in.HasRemaining()) return;
            m_addItems = _in.Read_list_pod<ItemShowPOD>(ItemShowPOD.DynamicFactory);
            if(!_in.HasRemaining()) return;
            m_itemCdInfo = _in.Read_map_int_int();
        }
		
		public UseItemResultPOD Clone() {
            UseItemResultPOD o = DynamicFactory();
            if (m_addItems != null) {
                o.m_addItems = m_addItems.ConvertAll(o => o?.Clone());
            }
            if (m_itemCdInfo != null) {
                o.m_itemCdInfo = new (m_itemCdInfo);
            }
            return o;
        }
        
        public void Clear() {
            m_addItems = default;
            m_itemCdInfo = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "UseItemResultPOD [";
			str += "addItems=";
			str += m_addItems.ToString<ItemShowPOD>();
			str += ", itemCdInfo=";
			str += m_itemCdInfo.ToString<int, int>();
			str += "]";
			return str;
		}
		
	}
}